<template>
    <view>
        <form @reset="formReset" @submit="formSubmit" :reportSubmit="true">
            <view class="main" :style="'background:' + color">
                <view class="top">
                    <image mode="aspectFill" :src="storeinfo.logo"></image>
                    <view class="topname" :style="'color:' + color">{{ storeinfo.name }}</view>
                </view>
                <view class="xx">
                    <view class="hyuan1" :style="'background:' + color"></view>
                    <view class="hyuan2" :style="'background:' + color"></view>
                </view>
                <view class="bottom" :style="'border-color:' + color">
                    <view class="pdlist">
                        <scroll-view :scrollY="true" style="height: 550rpx; background: #f5f5f5">
                            <view
                                @tap="select"
                                :class="'pdlistbd ' + (activeIndex == index ? 'czactive' : '')"
                                :data-index="index"
                                :style="'background:' + (activeIndex == index ? color : '') + ';color:' + (activeIndex == index ? '#fff' : '')"
                                v-for="(item, index) in tableinfo"
                                :key="index"
                            >
                                <view class="pdlistbdv">
                                    <view>{{ item.typename }}</view>
                                </view>
                            </view>
                        </scroll-view>
                    </view>
                    <view class="footer">
                        <button formType="submit" :style="'background:' + color">立即取号</button>
                    </view>
                    <view class="flex-row flex-y-center cxqh">
                        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/bangz.png"></image>
                        <view>过号请重新取号，谢谢配合！</view>
                    </view>
                </view>
            </view>
        </form>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
var util = require('../../utils/util.js');
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            store_id: '',

            storeinfo: {
                logo: '',
                name: ''
            },

            tableinfo: '',
            activeIndex: '',
            color: ''
        };
    },
    onLoad: function (e) {
        console.log(e);
        this.setData({
            store_id: e.storeid
        });
        uni.setNavigationBarTitle({
            title: '排队取号'
        });
        var that = this;
        app.globalData.setNavigationBarColor(this);
        app.globalData.getimgUrl(this);
        app.globalData.getUserInfo(function (t) {
            console.log(t);
            app.globalData.util.request({
                url: 'entry/wxapp/IsReceive',
                cachetime: '0',
                data: {
                    store_id: e.storeid,
                    user_id: t.id
                },
                success: function (t) {
                    console.log(t.data);
                    if (t.data && '1' == t.data.state) {
                        uni.redirectTo({
                            url: 'getnumdl?storeid=' + that.store_id + '&id=' + t.data.id
                        });
                    }
                }
            });
        });
        app.globalData.util.request({
            url: 'entry/wxapp/StoreInfo',
            cachetime: '0',
            data: {
                store_id: e.storeid
            },
            success: function (t) {
                console.log(t.data);
                that.setData({
                    storeinfo: t.data.store
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/GetTable',
            cachetime: '0',
            data: {
                store_id: e.storeid
            },
            success: function (t) {
                console.log(t.data);
                that.setData({
                    tableinfo: t.data
                });
            }
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function () {},
    methods: {
        select: function (t) {
            this.setData({
                activeIndex: t.currentTarget.dataset.index
            });
        },

        formSubmit: function (t) {
            var that = this;
            var a = this.store_id;
            var o = uni.getStorageSync('users').id;
            app.globalData.util.request({
                url: 'entry/wxapp/AddFormId',
                cachetime: '0',
                data: {
                    user_id: o,
                    form_id: t.detail.formId
                },
                success: function (t) {
                    console.log(t.data, o, a);
                }
            });
            if (null == this.activeIndex) {
                uni.showModal({
                    title: '提示',
                    content: '请选择桌位类型'
                });
            } else {
                uni.showModal({
                    title: '提示',
                    content: '您选择的是' + that.tableinfo[that.activeIndex].typename,
                    success: function (t) {
                        if (t.cancel) {
                            return true;
                        }
                        if (t.confirm) {
                            uni.showLoading({
                                title: '操作中'
                            });
                            app.globalData.util.request({
                                url: 'entry/wxapp/SaveNumber',
                                cachetime: '0',
                                data: {
                                    store_id: a,
                                    typename: that.tableinfo[that.activeIndex].typename,
                                    user_id: o
                                },
                                success: function (t) {
                                    console.log(t.data);
                                    if (t.data) {
                                        uni.showToast({
                                            title: '取号成功',
                                            icon: 'success',
                                            mask: true,
                                            duration: 1000
                                        });
                                        setTimeout(function () {
                                            uni.redirectTo({
                                                url: 'getnumdl?storeid=' + that.storeinfo.id + '&id=' + t.data
                                            });
                                        }, 1000);
                                    } else {
                                        uni.showToast({
                                            title: '请重试',
                                            icon: 'loading',
                                            duration: 1000
                                        });
                                    }
                                }
                            });
                        }
                    }
                });
            }
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        }
    }
};
</script>
<style>
@import './getnum.css';
</style>
